package com.yonyou.byb.rule;

import java.util.ArrayList;
import java.util.List;

import nc.bs.logging.Logger;
import nc.vo.pub.BusinessException;

import org.dom4j.Document;

import com.yonyou.byb.RespMsg;
import com.yonyou.byb.SaleOrder;
import com.yonyou.byb.bs.PayAbleBillBS;
import com.yonyou.byb.utils.PfxxDealTool;
import com.yonyou.nc.NCPayAbleBill;

public class TransactionRuleProcessor implements IRuleProcessor {

	@Override
	public List<RespMsg> process(SaleOrder[] saleorder) throws BusinessException {
		List<RespMsg> rlist = new ArrayList<>();
		
		try {
			PayAbleBillBS payablebs = new PayAbleBillBS();
			List<NCPayAbleBill>  list = payablebs.baodanToPayablebill(saleorder);
			Document payabledoc = payablebs.buildDoc(list);
			return new PfxxDealTool().dealWithDoc(payabledoc);
		} catch (BusinessException e) {
			Logger.error(e.getMessage(),e);
			rlist.add(RespMsg.error(saleorder[0].getBillid(),e.getMessage()));
		}
		
		return rlist;
	}

}
